package com.yugong.controller;

import com.yugong.common.Result;
import com.yugong.entity.vo.response.SystemListResponseVO;
import com.yugong.service.SystemService;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.ArrayList;
import java.util.List;

/**
 * 系统控制器类
 *
 * @author yugong
 * @date 2024/3/2
 */
@RestController
@RequestMapping("/api/system")
public class SystemController {
    @Resource
    private SystemService systemService;

    /**
     * 根据账号导出学生成绩表
     *
     * @param accountNo      账号
     * @param orderClassName 班名
     * @return 是否成功
     */
    @PostMapping("/export-student-score/{accountNo}")
    public Result exportStudentScoreExcel(@PathVariable String accountNo,
                                          @RequestBody String orderClassName) {
        boolean exportFlag = systemService.exportStudentScoreExcel(accountNo, orderClassName);
        return Result.success(exportFlag);
    }

    /**
     * 获取系统参数
     *
     * @param request http请求
     * @return 系统参数
     */
    @GetMapping("/get-system-parameter")
    public Result getSystemParameter(HttpServletRequest request) {
        SystemListResponseVO systemListResponseVO = systemService.getSystemParameter(request);
        List<SystemListResponseVO> systemListResponseVOList = new ArrayList<>();
        systemListResponseVOList.add(systemListResponseVO);
        return Result.success(systemListResponseVOList);
    }

    /**
     * 导入学生Excel文件
     *
     * @param file Excel文件
     * @return 文件名
     */
    @PostMapping("/upload-student-excel")
    public Result uploadStudentExcel(MultipartFile file) {
        String excelPath = systemService.uploadStudentExcel(file);
        return Result.success(excelPath);
    }

    /**
     * 导入教师Excel文件
     *
     * @param file Excel文件
     * @return 文件名
     */
    @PostMapping("/upload-teacher-excel")
    public Result uploadTeacherExcel(MultipartFile file) {
        String excelPath = systemService.uploadTeacherExcel(file);
        return Result.success(excelPath);
    }

    /**
     * 导入订单班管理员Excel文件
     *
     * @param file Excel文件
     * @return 文件名
     */
    @PostMapping("/upload-order-class-admin-excel")
    public Result uploadOrderClassAdminExcel(MultipartFile file) {
        String excelPath = systemService.uploadOrderClassAdminExcel(file);
        return Result.success(excelPath);
    }
}
